#include "progressbarwidget.h"
#include "ui_progressbarwidget.h"

ProgressBarWidget::ProgressBarWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::ProgressBarWidget)
{
    ui->setupUi(this);

    ui->progressBar->setRange(0,100);

    ui->progressBar->setAlignment(Qt::AlignCenter);
}

ProgressBarWidget::~ProgressBarWidget()
{
    delete ui;
}

void ProgressBarWidget::setValue(float value)
{
    if(value > 100)
        value = 100;
    else if(value < 0)
        value = 0;

    // 动态设置颜色
    // if(value < 50)
    // QPalette palette = ui->progressBar->palette();
    // palette.setColor(QPalette::Text,Qt::white);

    QString str = QString::asprintf("%.2f",value);
    ui->progressBar->setFormat(str);
    ui->progressBar->setValue((int)value);

}


